package com.weaver.qfengx;

import org.apache.commons.lang.time.DateUtils;
import tebie.applib.api.L;
import weaver.general.Util;

import java.util.Date;
import java.util.concurrent.*;

/**
 * 多线程相关工具类
 * Created by YeShengtao on 2020/9/27 12:08
 */
public class ThreadUtils {

    private static ThreadPoolExecutor executor = null;

    /**
     * 单例模式返回ThreadPoolExecutor - 5, 5, 0L
     * @return ThreadPoolExecutor
     */
    public static ThreadPoolExecutor getPoolExecutor() {
        if (executor != null) {
            return executor;
        } else {
            synchronized (ThreadUtils.class) {
                if (executor == null) {
                    executor = new ThreadPoolExecutor(5, 5, 0L,
                            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
                }
            }
        }
        return executor;
    }

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        System.out.println(111);
        ThreadUtils.getPoolExecutor().submit(() -> {
            Date now = new Date();
            double xysjVal = Util.getDoubleValue("3.00", 0f);
            double jjsjVal = Util.getDoubleValue("5.00", 0f);
            System.out.println(xysjVal);
            System.out.println(jjsjVal);
            double xysjTime = xysjVal * 3600;
            double jjsjTime = jjsjVal * 3600;
            Date xysjDate = DateUtils.addSeconds(now, new Double(xysjTime).intValue());
            Date jjsjDate = DateUtils.addSeconds(now, new Double(jjsjTime).intValue());
            System.out.println(com.weaver.qfengx.DateUtils.date(xysjDate));
            System.out.println(com.weaver.qfengx.DateUtils.date(xysjDate, "HH:mm"));
            System.out.println(com.weaver.qfengx.DateUtils.date(jjsjDate));
            System.out.println(com.weaver.qfengx.DateUtils.date(jjsjDate, "HH:mm"));
        });
        System.out.println(222);
    }

}
